import typeOfUtils from "../../../utils/type-of-utils";
import RenderUtils from "../RenderUtils";
import {RenderTypeItem} from "../ConfigType";

const rate: RenderTypeItem = {
  name: 'rate',
  /**
   *
   * @param createElement
   * @param vm
   * @param formItem
   * @return {VNode[]}
   */
  render(createElement, vm, formItem) {
    let colors = formItem.props.colors || []
    if (typeOfUtils.isEmpty(colors) && typeOfUtils.isFunction(formItem.props.setColors)) {
      colors = formItem.props.setColors() || []
    }
    let texts = formItem.props.texts || []
    if (typeOfUtils.isEmpty(texts) && typeOfUtils.isFunction(formItem.props.setTexts)) {
      texts = formItem.props.setTexts() || []
    }
    const config = RenderUtils.getConfig(vm, formItem, {
      props: {
        texts,
        colors,
      },
    }, this)
    return [
      createElement(`el-rate`, config)
    ]
  }
}

export default rate
